import json

from django.http import JsonResponse
from django.shortcuts import render

# Create your views here.
from django.views import View
from rest_framework.response import Response
from rest_framework.views import APIView

from apps.index.models import Content, Gedan, Gequ
from apps.index.serializers import IndexSerializer, GedanSerializer_v2, GequSerializer


class IndexView(APIView):
    '''主页'''

    def get(self, request):
        queryset=Content.objects.all()
        # 序列化
        # 轮播
        serializer=IndexSerializer(queryset,many=True)
        data=serializer.data
        #  歌单
        queryset1=Gedan.objects.all()
        serializer1=GedanSerializer_v2(queryset1,many=True)
        text=serializer1.data
        # 歌曲
        queryset2=Gequ.objects.all()
        serializer2=GequSerializer(queryset2,many=True)
        gequ=serializer2.data
        content={
            'data':data,
            'gedan':text,
            'gequ':gequ
        }
        # print(content)

        return JsonResponse(content)
